<template>
  <div>
      <city-header></city-header>
      <city-search
        :city="cities"
      >
      </city-search>
      <city-list
        :hotCity="hotCities"
        :city="cities"
        :getLetter="letter"
      >
      </city-list>
      <city-alphabet
        :alphabet="cities"
        @changeAlphabet="getAlphabet"
      >
      </city-alphabet>
  </div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'

export default {
  name: 'City',
  data () {
    return {
      hotCities: '', // 热门城市——数组
      cities: '', // 城市列表——对象
      letter: ''
    }
  },
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  methods: {
    getCityList () {
      axios.get('/api/city.json').then(this.getInfoSuccess)
    },
    getInfoSuccess (response) {
      if (response.data.ret === true) {
        const res = response.data.data
        this.hotCities = res.hotCities
        this.cities = res.cities
      } else {
        console.log('error')
      }
    },
    getAlphabet (data) {
      this.letter = data
    }
  },
  mounted () {
    console.log('mounted22')
    this.getCityList()
  },
  activated () {
    console.log('activated22')
  }
}
</script>

<style lang="stylus" scope>
</style>
